<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>欢迎使用领捷智慧物流管理系统</title>
    <link rel="hshortcut icon" href="../static/img/own/head.png"/>
    <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i">
    <link rel="stylesheet" href="/static/fonts/fontawesome-all.min.css">
</head>

<body id="page-top">
<div id="wrapper">
    <div class="d-flex flex-column" id="content-wrapper">
        <div id="content">
            <div class="container text-break text-center" style="max-width: 1547px;height: 88px;margin-bottom: 10px;">
                <div class="card row" style="margin: 0px;">
                    <div class="card-body" style="height: 79px;min-width: 0px;">
                        <div class="row">
                            <div class="col" style="width: auto;">
                                <div class="dropdown text-center" style="text-align: right;">
                                    <input style="height: 38px" type="text" placeholder="供应商序号" id="supid" name="supid">
                                </div>
                            </div>
                            <div class="col" style="width: auto;">
                                <div class="dropdown text-xl-center" style="text-align: right;">
                                    <input style="height: 38px" type="text" placeholder="供应商名字" id="supname" name="supname">
                                </div>
                            </div>
                            <div class="col" style="width: auto;">
                                <div class="dropdown text-xl-center" style="text-align: right;">
                                    <input style="height: 38px" type="text" placeholder="供应商电话" id="supphone" name="supphone">
                                </div>
                            </div>
                            <div class="col align-self-center" style="width: auto;">
                                <div class="btn-group" role="group" style="padding-left: 1px;"><button class="btn btn-primary" type="button" id="searchSupplierByKey">查询</button>
                                    <button class="btn btn-primary" type="button" style="margin-left: 5px;" id="clean">重置</button></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="container-fluid">
                <div class="card shadow">
                    <div class="card-header py-3" style="height: 75px;">
                        <div class="row" style="width: auto;height: auto;">
                            <div class="col">
                                <div class="btn-group" role="group"><button class="btn btn-primary" type="button" style="width: 120px;" id="addSupplier">新增</button>
                                    <button class="btn btn-primary" type="button" style="margin-left: 5px;width: 120px;" id="deleteSupplier">删除</button></div>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive table mt-2" role="grid" aria-describedby="dataTable_info">
                            <table class="table my-0" >
                                <thead style="height: 71px;">
                                <tr style="height: 60px;text-align: center">
                                    <th style="width: 150px;height: 60px;"><input type="checkbox" style="margin-left: 1px;" id="selectAll">供应商序号</th>
                                    <th style="width: auto;text-align: center;">供应商名称</th>
                                    <th>供应商电话</th>
                                    <th>供应商地址</th>
                                </tr>
                                </thead>
                                <tbody id="supplier" style="text-align: center">
                                </tbody>
                                <tfoot>
                                <tr></tr>
                                </tfoot>
                            </table>
                        </div>
                        <div class="row">
                            <div class="col-md-6 align-self-center">
                                <p id="dataTable_info" class="dataTables_info" role="status" aria-live="polite">Showing 1 to 10 of 27</p>
                            </div>
                            <div class="col-md-6">
                                <nav class="d-lg-flex justify-content-lg-end dataTables_paginate paging_simple_numbers">
                                    <ul class="pagination">
                                        <li class="page-item disabled"><a class="page-link" href="#" aria-label="Previous"><span aria-hidden="true">«</span></a></li>
                                        <li class="page-item active"><a class="page-link" href="#">1</a></li>
                                        <li class="page-item"><a class="page-link" href="#">2</a></li>
                                        <li class="page-item"><a class="page-link" href="#">3</a></li>
                                        <li class="page-item"><a class="page-link" href="#" aria-label="Next"><span aria-hidden="true">»</span></a></li>
                                    </ul>
                                </nav>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <footer class="bg-white sticky-footer">
            <div class="container my-auto">
                <div class="text-center my-auto copyright"><span>鄂ICP备2021022432号</span></div>
            </div>
        </footer>
    </div><a class="border rounded d-inline scroll-to-top" href="#page-top"><i class="fas fa-angle-up"></i></a></div>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/js/chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.js"></script>
<script src="/static/js/script.min.js"></script>
<script src="/static/js/jquery.session.js"></script>

<script>

    // 初始化页面
    $(document).ready(function (){
        $.ajax({
            url: "/supplier/allSupplier",
            type: 'post',
            dataType:"json",
            success:function (result){
                let str = "";
                for(let i = 0; i < result.length; i++){

                    str +="<tr><td  class=\"checkSupplierId\"><input type=\"checkbox\" style=\"margin-left: 1px;\" class=\"checkOne\" name=\"checkbox\">" + result[i].supid +"</td>" +
                        "<td>" + result[i].supname + "</td>" +
                        "<td>" + result[i].supphone + "</td>" +
                        "<td>" + result[i].supad + "</td></tr>"
                }
                $("#supplier").append(str);
            }
        })
    })

    //重置
    $(function (){
        $("#clean").click(function (){
            $(location).attr("href","/page/toSupplier")
        })
    })

    //跳转新增页面
    $(function (){
        $("#addSupplier").click(function (){
            $(location).attr("href","/page/toSupplierAdd")
        })
    })

    //根据供应商号，供应商名称，供应商电话查询
    $(function (){
        $("#searchSupplierByKey").on("click",function (){
            var supid = $("#supid").val();
            var supname = $("#supname").val();
            var supphone = $("#supphone").val();

            $.ajax({
                url: "/supplier/searchSupplierByKey",
                type: 'post',
                data:{"supid":supid,"supname":supname,"supphone":supphone},
                dataType:"json",
                success:function (result){
                    $("#supplier").html("");
                    let str = "";
                    for(let i = 0; i < result.length; i++){

                        str +="<tr><td  class=\"checkSupplierId\"><input type=\"checkbox\" style=\"margin-left: 1px;\" class=\"checkOne\" name=\"checkbox\">" + result[i].supid +"</td>" +
                            "<td>" + result[i].supname + "</td>" +
                            "<td>" + result[i].supphone + "</td>" +
                            "<td>" + result[i].supad + "</td></tr>"
                    }
                    $("#supplier").append(str);
                }
            })
        })
    })


    //全选复选框
    $(function (){
        $("#selectAll").on("click",function (){
            var selectAll = document.getElementById("selectAll");
            // alert(selectAll.checked);
            if(selectAll.checked == true){
                var checkOnes = document.getElementsByClassName("checkOne");
                for(var i=0;i<checkOnes.length;i++){
                    checkOnes[i].checked=true;
                }
            }else{
                var checkOnes = document.getElementsByClassName("checkOne");
                for(var i=0;i<checkOnes.length;i++){
                    checkOnes[i].checked=false;
                }
            }
        })
    })

    //根据复选框删除供应商信息
    $(function (){
        $("#deleteSupplier").on("click",function (){
            var checkOnes = document.getElementsByClassName("checkOne");

            var obj = [];
            var k = 0;
            for(var i = 0;i < checkOnes.length;i++){
                if(checkOnes[i].checked){
                    // var id = $(".checkOrderId").parent('tr').children().eq(0).text();
                    let id = $(".checkSupplierId").eq(i).text();
                    // alert(id);
                    obj[k++]=id;
                }
            }
            // alert(obj);
            if(obj.length !== 0){

                if(window.confirm("确认删除吗？")){
                    $.ajax({
                        url: "/supplier/deleteSupplier",
                        type: 'post',
                        dataType:"json",
                        data: {obj:obj},
                        traditional:true,
                        success:function (result){
                            alert("删除成功！");
                            $(location).attr("href","/page/toSupplier")
                        }
                    })
                }else{

                }
            }else{
                alert("请选择条目!");
            }


        })
    })

    //session
    $.session.set("url",window.location.href);
</script>
</body>

</html>